<?php

abstract class Engine_Widget_Abstract {
	
	protected $options;
	protected $config;
	protected $theme;
	
	public function __construct(array $config = null) {
		$this->theme = new Theme_Layout();
		$this->config = $config;
		$this->init($this->loadOptions());
		return $this;
	}
	
	protected abstract function init(array $options);
	public abstract function run();
	
	protected function loadOptions() {
		$classname = get_class($this);
		$core_widgets = new Engine_Db_Table_CoreWidgets();
		$select = $core_widgets->select();
		$select->where("widget_classname = '$classname'");
		$results = $core_widgets->fetchRow($select);
		
		if (!isset($results['widget_options'])) {
			$this->options = unserialize($results['widget_options']);
		} else {
			$this->options = array();
		}
		
		return $this->options;
	}

	protected function getCache() {
		return Zend_Registry::get('Zend_Cache');
	}
	
	protected function getLog() {
		return Zend_Registry::get('Zend_Log');
	}
	
	protected function getTranslate() {
		return Zend_Registry::get('Zend_Translate');
	}
	
	protected function getAuthRecord() {
		$auth = Zend_Registry::get('WJAuth');
		return $auth->authRecord();
	}
	
	protected function getCurrency() {
		return Zend_Registry::get('Zend_Currency');
	}

	protected function getLocale() {
		return Zend_Registry::get('Zend_Locale');
	}

	protected function getSession() {
		return new Zend_Session_Namespace(get_class($this));
	}
	
	protected function getAcl() {
		return Zend_Registry::get('Zend_Acl');
	}

}
?>